<?php
/**
 ***********************************************************************************************************************
 * 客户管理专业版V1
 ***********************************************************************************************************************
 */

namespace soa\account;


class CrmV1 extends crm
{

    /**
     * 添加客户记录
     * 
     * @param array $dict
     * @return bool|null
     */
    public function add(array $dict)
    {
        if(empty($dict)) {
            return false;
        }
        return $this->post('v1/courier/CrmV1/add', $this->orzParams($dict));
    }

    /**
     * 删除客户；拉黑；移出黑名单
     * @param $id
     * @param string $isDeleted
     * @return bool|null
     */
    public function del($id, $isDeleted = '')                //此方法为重写方法；新增的参数默认为空
    {
        if(empty($id) || !is_numeric($id) || !isset($isDeleted)) {
            return false;
        }
        return $this->post('v1/courier/CrmV1/del', $this->orzParams(['id' => $id,'is_deleted' => $isDeleted ]));
    }

    /**
     * 更新客户记录
     *
     * @param $id
     * @param array $dict
     * @return bool|null
     */
    public function update($id, array $dict)
    {
        if(empty($id) || !is_numeric($id) || empty($dict)) {
            return false;
        }
        return $this->post('v1/courier/CrmV1/update', $this->orzParams(array_merge($dict, ['id' => $id])));
    }

    
    /**
     * 全量同步
     *
     * @param int $page
     * @param int $page_num
     * @return bool
     */
    public function syncAll($page = 1, $page_num = 1000)
    {
        $dict = [
            'page' => (int)$page,
            'page_num' => (int)$page_num
        ];
        return $this->post('v1/courier/CrmV1/syncAll', $this->orzParams($dict));
    }

    /**
     * 增量同步
     *
     * @param $last_sync_time* @param array $change
     * @param string $del_ids
     * @return bool
     */
    public function syncIncr($last_sync_time, array $change = [], $del_ids = '')
    {
        // 如果超过三个月没有同步,则只同步最近三个月更新数据
        $dict = [
            'last_sync_time' => (int)$last_sync_time < strtotime('-3 month') ? strtotime('-3 month') : (int)$last_sync_time,
            'change' => json_encode($change ? $change : []),
            'del_ids' => preg_replace('/\s+/', '', (string)$del_ids)
        ];
        return $this->post('v1/courier/CrmV1/syncIncr', $this->orzParams($dict));
    }

    /**
     * 获取财富值
     * @param $time
     * @return bool|null
     */
    public function getWealth($time){
        if(empty($time)){
            return false;
        }
        return $this->post('v1/courier/CrmV1/getWealth', $this->orzParams(['time' => $time]));
    }

    /**
     * 获取财富值在同网点所占比例
     * @param $time
     * @return bool|null
     */
    public function getWealthRatio($data){
        if(empty($data) || !is_array($data)){
            return false;
        }
        return $this->post('v1/courier/CrmV1/getWealthRatio', $this->orzParams($data));
    }


}